﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITAP.ShprossesBuilder.Modelling.Components;

namespace ITAP.ShprossesBuilder.Operations
{
    public class OperationUnstickHalfSunFromShpross : IOperation
    {
        #region IOperation Members

        public string Name
        {
            get { return "Отсоединить полусолнышко от профиля"; }
        }

        public OperationGroup OperationGroup
        {
            get { return OperationGroup.ShprossConnectorOperation; }
        }

        public System.Drawing.Image Thumbnail
        {
            get { return null; }
        }

        public void Execute(ModelControl modelControl)
        {
            foreach (IComponent selectedComponent in modelControl.ModelContainer.SelectedComponentsStack)
            {
                if (selectedComponent is ShprossConnector)
                {
                    ShprossConnector connector = selectedComponent as ShprossConnector;
                    if (connector.ShprossConnectorType == ShprossConnectorType.HalfSunRays)
                    {
                        List<IComponent> stickConnector = connector.Stub.InnerComponents.GetComponentsByType(typeof(StickConnector));
                        if (stickConnector.Count == 1)
                            stickConnector[0].DisconnectFromAll();
                    }
                }
            }
        }

        public bool CanUndo
        {
            get { return true; }
        }

        #endregion
    }
}
